library("doRedis")

registerDoRedis("jobs")
redisDelete("count")

# Setup some data
data(iris)
x <- iris[which(iris[,5] != "setosa"), c(1,5)]
trials <- 100000
chunkSize <- 100

# Start local workers
startLocalWorkers(n=4, queue="jobs")
setChunkSize(chunkSize)

# Run example
r <- foreach(icount(trials), .combine=cbind, .inorder=FALSE) %dopar% {
  redisIncrBy("count", chunkSize)
  ind <- sample(100, 100, replace=TRUE)
  estimate <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
  coefficients(estimate)
}

removeQueue("jobs")
